"""
变量练习题
==========
完成以下练习，巩固变量的使用
"""

print("=" * 60)
print(" " * 20 + "变量练习题")
print("=" * 60)
print()

# ==================== 练习1：基础变量操作 ====================
print("【练习1】基础变量操作")
print("-" * 60)

"""
任务：创建变量存储你的个人信息
- 姓名、年龄、城市、爱好
- 然后打印输出
"""

# 在这里写你的代码
my_name = "你的姓名"
my_age = 25
my_city = "你的城市"
my_hobby = "你的爱好"

print(f"姓名: {my_name}")
print(f"年龄: {my_age}")
print(f"城市: {my_city}")
print(f"爱好: {my_hobby}")

print()


# ==================== 练习2：变量交换 ====================
print("【练习2】变量交换")
print("-" * 60)

"""
任务：有两个杯子，A杯装着果汁，B杯装着牛奶
要求交换两个杯子的内容
"""

cup_a = "果汁"
cup_b = "牛奶"

print(f"交换前：A杯={cup_a}, B杯={cup_b}")

# 方法1：使用临时变量
# 在这里写你的代码

# 方法2：使用Python的优雅方式
cup_a, cup_b = cup_b, cup_a

print(f"交换后：A杯={cup_a}, B杯={cup_b}")

print()


# ==================== 练习3：类型转换 ====================
print("【练习3】类型转换")
print("-" * 60)

"""
任务：用户输入会得到字符串，需要转换成数字进行计算
计算长方形的面积
"""

# 假设从用户输入得到的数据（字符串格式）
length_str = "10"
width_str = "5"

# 转换为数字
length = int(length_str)
width = int(width_str)

# 计算面积
area = length * width

print(f"长方形长度: {length}米")
print(f"长方形宽度: {width}米")
print(f"长方形面积: {area}平方米")

print()


# ==================== 练习4：温度转换 ====================
print("【练习4】温度转换")
print("-" * 60)

"""
任务：实现摄氏度和华氏度的相互转换
公式：
- 华氏度 = 摄氏度 × 9/5 + 32
- 摄氏度 = (华氏度 - 32) × 5/9
"""

# 摄氏度转华氏度
celsius = 25
fahrenheit = celsius * 9/5 + 32
print(f"{celsius}°C = {fahrenheit}°F")

# 华氏度转摄氏度
fahrenheit2 = 77
celsius2 = (fahrenheit2 - 32) * 5/9
print(f"{fahrenheit2}°F = {celsius2:.2f}°C")

print()


# ==================== 练习5：圆的计算 ====================
print("【练习5】圆的计算")
print("-" * 60)

"""
任务：给定圆的半径，计算圆的周长和面积
公式：
- 周长 = 2 × π × 半径
- 面积 = π × 半径²
"""

# 定义常量
PI = 3.14159

# 圆的半径
radius = 5

# 计算周长和面积
circumference = 2 * PI * radius
area = PI * radius ** 2

print(f"圆的半径: {radius}")
print(f"圆的周长: {circumference:.2f}")
print(f"圆的面积: {area:.2f}")

print()


# ==================== 练习6：多变量赋值 ====================
print("【练习6】多变量赋值")
print("-" * 60)

"""
任务：使用多变量赋值方式，给三个变量赋值
- 方式1：同时赋相同值
- 方式2：同时赋不同值
"""

# 方式1：三个变量都赋值为0
score1 = score2 = score3 = 0
print(f"初始分数: {score1}, {score2}, {score3}")

# 方式2：三个变量赋不同的值
score1, score2, score3 = 85, 90, 78
print(f"实际分数: {score1}, {score2}, {score3}")

# 计算平均分
average = (score1 + score2 + score3) / 3
print(f"平均分: {average:.2f}")

print()


# ==================== 练习7：购物清单 ====================
print("【练习7】购物清单")
print("-" * 60)

"""
任务：创建一个简单的购物清单，计算总价
"""

# 商品信息
item1_name = "苹果"
item1_price = 5.5
item1_quantity = 3

item2_name = "香蕉"
item2_price = 3.8
item2_quantity = 2

item3_name = "橙子"
item3_price = 4.2
item3_quantity = 4

# 计算每种商品的小计
item1_total = item1_price * item1_quantity
item2_total = item2_price * item2_quantity
item3_total = item3_price * item3_quantity

# 计算总价
total_price = item1_total + item2_total + item3_total

# 打印购物清单
print("=" * 50)
print(" " * 18 + "购物清单")
print("=" * 50)
print(f"{item1_name:^10} {item1_price:>8.2f}元 × {item1_quantity} = {item1_total:>8.2f}元")
print(f"{item2_name:^10} {item2_price:>8.2f}元 × {item2_quantity} = {item2_total:>8.2f}元")
print(f"{item3_name:^10} {item3_price:>8.2f}元 × {item3_quantity} = {item3_total:>8.2f}元")
print("-" * 50)
print(f"{'总计':^10} {' ' * 19} {total_price:>8.2f}元")
print("=" * 50)

print()


# ==================== 练习8：BMI计算器 ====================
print("【练习8】BMI计算器")
print("-" * 60)

"""
任务：计算身体质量指数（BMI）
公式：BMI = 体重(kg) / 身高(m)²

BMI分类：
- < 18.5: 偏瘦
- 18.5 ~ 24.9: 正常
- 25 ~ 29.9: 偏胖
- >= 30: 肥胖
"""

# 个人信息
person_name = "张三"
weight = 70  # 千克
height = 1.75  # 米

# 计算BMI
bmi = weight / (height ** 2)

# 判断体型（简单判断）
if bmi < 18.5:
    status = "偏瘦"
elif bmi < 25:
    status = "正常"
elif bmi < 30:
    status = "偏胖"
else:
    status = "肥胖"

print(f"姓名: {person_name}")
print(f"体重: {weight}kg")
print(f"身高: {height}m")
print(f"BMI指数: {bmi:.2f}")
print(f"体型状态: {status}")

print()


# ==================== 练习9：变量作用域 ====================
print("【练习9】变量作用域")
print("-" * 60)

"""
任务：理解全局变量和局部变量的区别
"""

# 全局变量
total_count = 0

def add_count(n):
    """增加计数"""
    global total_count
    total_count += n
    local_var = f"本次增加{n}"
    print(f"  {local_var}, 当前总数: {total_count}")

print(f"初始计数: {total_count}")
add_count(5)
add_count(3)
add_count(7)
print(f"最终计数: {total_count}")

print()


# ==================== 练习10：综合应用 ====================
print("【练习10】综合应用：成绩管理系统")
print("-" * 60)

"""
任务：创建一个学生成绩管理系统
包含：学生信息、各科成绩、统计分析
"""

# 学生信息
STUDENT_ID = "2024001"  # 常量
student_name = "李明"
grade = "高三"
class_num = "1班"

# 科目成绩
subject_chinese = "语文"
score_chinese = 88
subject_math = "数学"
score_math = 95
subject_english = "英语"
score_english = 82
subject_physics = "物理"
score_physics = 90
subject_chemistry = "化学"
score_chemistry = 85

# 统计计算
total_score = score_chinese + score_math + score_english + score_physics + score_chemistry
subject_count = 5
average_score = total_score / subject_count
max_score = max(score_chinese, score_math, score_english, score_physics, score_chemistry)
min_score = min(score_chinese, score_math, score_english, score_physics, score_chemistry)

# 输出成绩报告
print("┏" + "━" * 58 + "┓")
print(f"┃{' ' * 20}学生成绩报告{' ' * 24}┃")
print("┣" + "━" * 58 + "┫")
print(f"┃ 学号: {STUDENT_ID:<50}┃")
print(f"┃ 姓名: {student_name:<50}┃")
print(f"┃ 年级: {grade:<50}┃")
print(f"┃ 班级: {class_num:<50}┃")
print("┣" + "━" * 58 + "┫")
print(f"┃ {subject_chinese}: {score_chinese}分{' ' * 46}┃")
print(f"┃ {subject_math}: {score_math}分{' ' * 46}┃")
print(f"┃ {subject_english}: {score_english}分{' ' * 46}┃")
print(f"┃ {subject_physics}: {score_physics}分{' ' * 46}┃")
print(f"┃ {subject_chemistry}: {score_chemistry}分{' ' * 46}┃")
print("┣" + "━" * 58 + "┫")
print(f"┃ 总分: {total_score}分{' ' * 46}┃")
print(f"┃ 平均分: {average_score:.2f}分{' ' * 43}┃")
print(f"┃ 最高分: {max_score}分{' ' * 46}┃")
print(f"┃ 最低分: {min_score}分{' ' * 46}┃")
print("┗" + "━" * 58 + "┛")

print()


# ==================== 结束 ====================
print("=" * 60)
print("✅ 所有练习完成！")
print("💡 提示：尝试修改变量的值，观察输出的变化")
print("📚 继续学习其他Python知识点吧！")
print("=" * 60)

